// SPDX-License-Identifier: GPL-3.0-or-later

import QtQuick
import QtQuick.Layouts

import Fk
import Fk.Components.LunarLTK
import Fk.Pages.LunarLTK
import Fk.Components.Common

ColumnLayout {
  id: root
  anchors.fill: parent
  property var extra_data: ({ name: "", data: {} })
  signal finish()

  BigGlowText {
    Layout.fillWidth: true
    Layout.preferredHeight: childrenRect.height

    text: Lua.tr(extra_data.name)
  }

  GridView {
    cellWidth: 130
    cellHeight: 170
    Layout.preferredWidth: root.width - root.width % 97
    Layout.fillHeight: true
    Layout.alignment: Qt.AlignHCenter
    clip: true

    model: extra_data.data.map(data => {
      const player = Lua.evaluate(
        `(function()
          local player = ClientInstance:getPlayerById(${data[0]})
          return {
            id = player.id,
            general = player.general,
            deputyGeneral = player.deputyGeneral,
            screenName = player.player:getScreenName(),
            kingdom = player.kingdom,
            seat = player.seat,
            role = 'hidden',
          }
        end)()`
      );
      player.tip = data[1];
      return player;
    });

    delegate: Photo {
      scale: 0.65
      playerid: modelData.id
      general: modelData.general
      deputyGeneral: modelData.deputyGeneral
      role: modelData.role
      state: "candidate"
      screenName: modelData.screenName
      kingdom: modelData.kingdom
      seatNumber: modelData.seat
      selectable: true

      GlowText {//显示文本
        anchors.centerIn: parent
        text: Lua.tr(modelData.tip)
        visible: true
        font.family: Config.libianName
        font.pixelSize: 70
        font.bold: true
        color: "#FEF7D6"
        glow.color: "#845422"
        glow.spread: 0.8
      }

      Component.onCompleted: {
        this.visibleChildren[12].visible = false;
      }
    }
      
  }
}
